import { PSControlObjectImpl } from '../pscontrol-object-impl';
import { IPSChartCoordinateSystem } from './ipschart-coordinate-system';
import { IPSChartCoordinateSystemControl } from './ipschart-coordinate-system-control';
import { IPSDEChart } from './ipsdechart';

export class PSDEChartCoordinateSystemControlImplBase extends PSControlObjectImpl implements IPSChartCoordinateSystemControl {
  get baseOptionJOString(): string {
    return this.M.baseOptionJOString;
  }

  get index(): number {
    return this.M.index;
  }

  protected pschartcoordinatesystem: IPSChartCoordinateSystem | null = null;

  getPSChartCoordinateSystem(): IPSChartCoordinateSystem | null {
    if (this.pschartcoordinatesystem != null) return this.pschartcoordinatesystem;
    const value = this.M.getPSChartCoordinateSystem;
    if (value == null) {
      return null;
    }
    const ipsdechart = this.getParentPSModelObject('control.chart.IPSDEChart') as IPSDEChart;
    if (ipsdechart != null) {
      this.pschartcoordinatesystem = ipsdechart.findPSChartCoordinateSystem(value);
    }
    return this.pschartcoordinatesystem;
  }

  get psChartCoordinateSystem(): IPSChartCoordinateSystem | null {
    return this.getPSChartCoordinateSystem();
  }

  getPSChartCoordinateSystemMust(): IPSChartCoordinateSystem {
    const value = this.getPSChartCoordinateSystem();
    if (value == null) {
      throw new Error('未指定图表坐标系统');
    }
    return value;
  }

  get type(): string {
    return this.M.type;
  }

  get cls(): string {
    return 'PSDEChartCoordinateSystemControlImplBase';
  }

  instanceof(cls: string): boolean {
    if (cls == 'control.chart.IPSChartCoordinateSystemControl') return true;
    return super.instanceof(cls);
  }
}
